/*
 * @Description: 任务航线，降落航线
 * @Date: 2022-04-08 15:49:58
 * @Author: yeming
 */

import { LineString } from 'ol/geom'
import { Point, Point3d } from './work/draw/point.js'
import { Line, Line3d } from './work/draw/line.js'
import { Circle, Circle3d } from './work/draw/circle.js'

class Airline {
  constructor(ol2d, ol3d, airlineHashMap, taskPointHashMap, landPointHashMap, guidePointHashMap, airCircleHashMap, airPointSource, airlineSource, airCircleSource) {
    this.ol2d = ol2d
    this.entities = ol3d.entities
    this.airlineHashMap = airlineHashMap // 航线
    this.taskPointHashMap = taskPointHashMap // 任务航点/线
    this.landPointHashMap = landPointHashMap // 降落航点/线
    this.guidePointHashMap = guidePointHashMap // 引导点/线
    this.airCircleHashMap = airCircleHashMap // 盘旋圈
    this.airPointSource = airPointSource
    this.airlineSource = airlineSource
    this.airCircleSource = airCircleSource
  }

  addTaskLine (sessionId, list) {
    for (let i = 0; i < list.length; i++) {

      this.addPoint(list[i].id, list[i].latlng, list[i].type, list[i].num, list[i].prefix, list[i].isHover, list[i].radius, list[i].isEdit, list[i].style, list[i].parentId, list[i].parentType, this.taskPointHashMap)

      this.addCircle(list[i].id, 1, list[i].latlng, list[i].isHover, list[i].radius, list[i].style, false)

    }

    this.airlineHashMap.set(sessionId, { 'task': this.taskPointHashMap, 'land': this.landPointHashMap, 'guide': this.guidePointHashMap, 'circle': this.airCircleHashMap })
  }

  addLandLine (sessionId, list) {
    for (let i = 0; i < list.length; i++) {

      this.addPoint(list[i].id, list[i].latlng, list[i].type, list[i].num, list[i].prefix, list[i].isHover, list[i].radius, list[i].isEdit, list[i].style, list[i].parentId, list[i].parentType, this.landPointHashMap)

      this.addCircle(list[i].id, 1, list[i].latlng, list[i].isHover, list[i].radius, list[i].style, false)

    }

    this.airlineHashMap.set(sessionId, { 'task': this.taskPointHashMap, 'land': this.landPointHashMap, 'guide': this.guidePointHashMap, 'circle': this.airCircleHashMap })

  }

  addGuideLine (sessionId, type, list) {

  }

  addPoint (id, latlng, type, num, prefix, isHover, radius, isEdit, style, parentId, parentType, pointHashMap) {
    let point = new Point(this.ol2d, this.airPointSource)
    point.addPoint(id, latlng, type, num, prefix, isHover, radius, isEdit, style, parentId, parentType)

    let color3d = style.fillColor || 'rgba(0, 153, 255, 1)'
    let label3d = prefix + String(num)
    let position = new Cesium.Cartesian3.fromDegrees(latlng[0], latlng[1], latlng[2] || 80)
    let point3d = new Point3d(this.entities, 'airPoint3d_' + id, type, color3d, label3d)
    point3d.position = position

    pointHashMap.set(id, { 'item2d': point, 'item3d': point3d })
  }

  addCircle (id, type, latlng, isHover, radius, style, rend3d) {
    if (!isHover) return false

    let circle = new Circle(this.ol2d, this.airCircleSource)
    circle.addCircle(id, type, latlng, isHover, radius, style, rend3d)

    let circle3d = new Circle3d(this.entities, 'airCircle3d_' + id, type, latlng, radius, style, rend3d)
    circle3d.position = position

    this.airCircleHashMap.set(id, { 'item2d': circle, 'item3d': circle3d })
  }

  /**
   * @desc: 添加单线（没有点等其他内容物）
   * @param {*} id
   * @param {*} latlng
   * @param {*} style
   * @param {*} rend3d
   * @param {*} isDash
   * @return {*}
   * @use: 使用示例
   */
  addNormalLine (id, latlng, style, rend3d, isDash) {

  }
}

export default Airline
